<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LaborCompanyContract extends Model
{
    use HasFactory;

    protected $fillable = [
        'labor_company_id',
        'admin_id',
        'role_id',
        'company_id',
        'name',
        'bank',
        'bank_number',
        'price',
        'duration',
        'service_fee_ratio',
        'contract_num',
        'contact',
        'contract_type',
        'earnest_money',
        'warranty_period',
        'contracting_method',
        'payment_currency',
        'construction_content',
        'pay_method',
        'files',
        'remarks',
        'start_date',
        'end_date',
    ];
    const POSTONLY = [
        'labor_company_id',
        'admin_id',
        'role_id',
        'company_id',
        'name',
        'bank',
        'bank_number',
        'price',
        'duration',
        'service_fee_ratio',
        'contract_num',
        'contact',
        'contract_type',
        'earnest_money',
        'warranty_period',
        'contracting_method',
        'payment_currency',
        'construction_content',
        'pay_method',
        'files',
        'remarks',
        'start_date',
        'end_date',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function resources()
    {
        return $this->hasMany(ResourceBind::class,'source_id','id')->where('model','LaborCompanyContract')->with('resource');
    }

}
